/** FASSIT (Forms of Selective Attention in Intelligent Transportation Systems)
 * Computational Creativity and Digital Media
 * Cognitive and Media Systems Group
 * Centre for Informatics and Systems of the University of Coimbra (CISUC)
 *
 * Copyright (c) 2010-2013 University of Coimbra, Portugal
 * All rights reserved.
 */

package poi.UncertaintyCalculator;

import java.util.HashMap;

import masterAgent.DBmanager.DBConnection;
import poi.Info.POI;
import poi.Uncertainty.*;
import agent.Context.Goal;

/**
 * This class is used to calculate the Master agent Uncertainty for the all the
 * parameters DayOff, Price and Schedule
 * 
 * @author Hernani Costa
 * @version 0.1 date: 27/01/2013
 */
public class UncertaintyCalculatorForPOI {

	UncertaintyCalculatorForSchedule schedule;
	HashMap<Integer, UncertaintySchedule> poiUncertaintySchedule;
	UncertaintyCalculatorForDaysOff daysOff;
	HashMap<Integer, UncertaintyDaysOff> poiUncertaintyDayOff;
	UncertaintyCalculatorForPrice price;
	HashMap<Integer, UncertaintyPrice> poiUncertaintyPrice;

	/**
	 * ------------------------------------------------------------------------
	 * Constructor class
	 * ------------------------------------------------------------------------
	 * 
	 * @param pois - list with the POIs that we intend to calculate the Uncertainty
	 */
	public UncertaintyCalculatorForPOI(HashMap<Integer,POI> pois) {
		schedule = new UncertaintyCalculatorForSchedule(pois);
		poiUncertaintySchedule = schedule.getPoiUncertaintySchedule();
		daysOff = new UncertaintyCalculatorForDaysOff(pois);
		poiUncertaintyDayOff = daysOff.getPoiUncertaintyDayOff();
		price = new UncertaintyCalculatorForPrice(pois);
		poiUncertaintyPrice = price.getPoiUncertaintyPrice();
	}

	// ------------------------------------------------------------------------
	// ------------------------GETs and SETs-----------------------------------
	// ------------------------------------------------------------------------

	public HashMap<Integer, UncertaintySchedule> getPoiUncertaintySchedule() {
		return poiUncertaintySchedule;
	}

	public HashMap<Integer, UncertaintyDaysOff> getPoiUncertaintyDayOff() {
		return poiUncertaintyDayOff;
	}

	public HashMap<Integer, UncertaintyPrice> getPoiUncertaintyPrice() {
		return poiUncertaintyPrice;
	}

	public String to_String() {
		String info = "";
		for (int poiID : poiUncertaintyDayOff.keySet()) {
			info += "poiID: " + poiID + "\n";
			info += "\t" + poiUncertaintyDayOff.get(poiID).to_String() + "\n";
			info += "\t" + poiUncertaintySchedule.get(poiID).to_String() + "\n";
			info += "\t" + poiUncertaintyPrice.get(poiID).to_String() + "\n";
		}
		return info;
	}

	/**
	 * ------------------------------------------------------------------------
	 * Only for debug purpose
	 * ------------------------------------------------------------------------
	 */
	public static void main(String args[]) {
		// DBManager manager = new DBManager();
		DBConnection connector = new DBConnection();

		POI poi = connector.getPOI(1507669);
		// System.err.println("O pesquisado\n" + poi.to_String() + "\n\n");

		HashMap<Integer,POI> pois = connector.getPOIsNear(poi.getLocation(),
				200, new Goal().getCoffee());
		// for (POI p : pois) {
		// System.err.println(p.to_String());
		// }

		UncertaintyCalculatorForPOI m = new UncertaintyCalculatorForPOI(pois);
		System.out.println(m.to_String());
	}
}
